#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    void hammingWeight(vector<int>& v, uint32_t n) {
        int cnt = 0;
        for (int i = 0; i < 32; i++)
        {
            if ((n >> i) & 1)
                cnt++;
        }
        v.push_back(cnt);
    }
    vector<int> countBits(int n) {
        vector<int> v;
        v.reserve(n + 1);
        for (int i = 0; i <= n; i++)
        {
            hammingWeight(v, i);
        }
        return v;
    }
};